home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / VOXRAY.ZIP / MEMUTIL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-25  |  956 b   |  45 lines

  1. #ifndef _MEMUTIL_
  2. #define _MEMUTIL_
  3. #include "types.h"
  4. #include "error.h"
  5. #include <stdlib.h>
  6. #include <mem.h>
  7.  
  8. #define MEM_ID_1 0x12
  9. #define MEM_ID_2 0x34
  10.  
  11. inline UCHAR * NewPtr(unsigned long x)
  12. {
  13.     if (x==0)
  14.       return NULL;
  15.     UCHAR * temp=(UCHAR *)new UCHAR [x+2];
  16.     if ((temp==NULL))
  17.               Error("Memory Allocation Failed!");
  18.     temp[0]=MEM_ID_1;
  19.     temp[1]=MEM_ID_2;
  20.     memset(temp+2, 0xCC, x);
  21.     return (temp+2);
  22. };
  23.  
  24. inline void DelPtr(PVOID orig_ptr) {
  25.   if (orig_ptr==NULL)
  26.      Error("Attempt to delete NULL ptr");
  27.   PUCHAR ptr_temp=(PUCHAR)orig_ptr-2;
  28.   if (ptr_temp[0]!=MEM_ID_1) {
  29.      Error("Bad Pointer Deletion");
  30.   }
  31.   if (ptr_temp[1]!=MEM_ID_2) {
  32.      Error("Bad Pointer Deletion");
  33.   }
  34.   delete ptr_temp;
  35. }
  36.  
  37. inline UCHAR * PtrRealloc(PVOID orig_ptr, unsigned long x) {
  38.          UCHAR * temp=(UCHAR *)realloc(orig_ptr, x);
  39.          if ((temp==NULL)&&(x!=0))
  40.              Error("Memory Reallocation Failed!");
  41.          return (temp);
  42. }
  43.  
  44. #endif
  45.